package com.yanchengtect.demo.progress.rollback.activity.dao;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.yanchengtect.demo.progress.dao.BaseDao;
import com.yanchengtect.demo.progress.dao.RowMapperUtil;
import com.yanchengtect.demo.progress.rollback.activity.domain.Apply;
import com.yanchengtect.demo.progress.rollback.activity.dto.ApplyDto;

/**
* @author 文心雕龙 Email：xuwenlong@shike8888.com
* @version 创建时间：2018年9月6日 下午7:19:58
* 类说明
*/
@Repository
public class ApplyDao extends BaseDao<Apply> {

	/**
	 * 根据活动id和用户id查询申请信息
	 * @param uid 用户id
	 * @param actId 活动id
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ApplyDto findByUidAndAid(Integer uid, int actId) {
		String sql = "SELECT a.apply_id,a.apply_status,t.first_time,t.second_time from apply a \n" + 
				"left join task t on a.apply_id = t.apply_id\n" + 
				"where a.user_id = ? and a.act_id = ? ";
		log.debug(sql);
		List<ApplyDto> list = jdbcTemplate.query(sql, new Object[] {uid,actId},new RowMapperUtil(ApplyDto.class));
		  
		  if (list.size()>0) {
			return list.get(0);
		 }else {
			 return null;
		 }
	}
	
	
	/**
	 * 根据对象更新记录
	 * @param apply
	 * @return
	 */
	public int updateOne(Apply apply) {
		
		HashMap<String,Object> conditions = new HashMap<String, Object>();
		conditions.put("apply_id", apply.getApply_id());
		apply.setApply_id(null);
		return update("apply", apply, conditions);
		
	}

}
